<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class OptionRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $itemId = $this->item->id??$this->option->input_item_id??0;
        $optionId = $this->option->id??0;
        return [
            'option_name' => ['required', 'max:100', Rule::unique('input_options')->where(function($q) use($itemId){
                return $q->where('input_item_id', $itemId);
            })->ignore($optionId)],

            'option' => ['required', 'numeric', Rule::unique('input_options')->where('input_item_id', $itemId)->ignore($optionId)],

            'rate' => 'required|numeric',
        ];
    }
}
